
//Definition for a binary tree node.
class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode() {}
    TreeNode(int val) { this.val = val; }
    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}

class Solution {
    public boolean evaluateTree(TreeNode root) {
        // 递归的出口
        if(root.val == 0){
            return false;
        }
        if(root.val == 1){
            return true;
        }
        // 计算左子树和右子树 再根据左右子树计算根节点
        boolean left = evaluateTree(root.left);
        boolean right = evaluateTree(root.right);
        if(root.val == 2){
            return (left || right);
        }else{
            return (left && right);
        }
    }
}